!> author: 左志华
!> date: 2022-07-16
!>
!> 测试 math 和 ti_sph_kind 模块
module test_math_m

    use testdrive, only: new_unittest, unittest_type, error_type, check
    use sph_kinds, only: rk
    use sph_math
    implicit none
    private

    public :: collect_math

contains

    subroutine collect_math(testsuite)
        type(unittest_type), intent(out), allocatable :: testsuite(:)

        allocate (testsuite, source=[ &
                  new_unittest("FUNC: get_distance", test_get_distance), &
                  new_unittest("PARA: rk", test_rk) &
                  ])

    end subroutine collect_math

    subroutine test_get_distance(error)
        type(error_type), intent(out), allocatable :: error
        real(rk) :: x(2) = [0.0_rk, 0.0_rk], y(2) = [1.0_rk, 1.0_rk]
        real(rk) :: d(2), r

        call get_distance(x, y, d, r)
        call check(error, all(abs(d + 1.0_rk) < const(1)), more="distance")
        if (allocated(error)) return

        call check(error, r, sqrt(2.0_rk), more="radius")

    end subroutine test_get_distance

    subroutine test_rk(error)
        type(error_type), intent(out), allocatable :: error

        call check(error, rk, 8, more="real number kind")

    end subroutine test_rk

end module test_math_m
